package cn.ycl.system.other.test;

import lombok.SneakyThrows;

import java.util.concurrent.Semaphore;

/**
 * @author YuanChangLiang
 * @description
 * @date created in 8:49 2022/2/22
 */


public class ThreadAbc {
    private static Semaphore A = new Semaphore(1);
    private static Semaphore B = new Semaphore(0);
    private static Semaphore C = new Semaphore(0);

    static class ThreadA extends Thread{
        @SneakyThrows
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                A.acquire();
                System.out.println("A");
                B.release();
            }
        }
    }

    static class ThreadB extends Thread{
        @SneakyThrows
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                B.acquire();
                System.out.println("B");
                C.release();
            }
        }
    }

    static class ThreadC extends Thread{
        @SneakyThrows
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                C.acquire();
                System.out.println("C");
                A.release();
            }
        }
    }
    public static void main(String[] args) {
        new ThreadA().start();
        new ThreadB().start();
        new ThreadC().start();
    }
}

